package exercise;

import java.util.ArrayList;
import java.util.List;

public class LCode1281 {
    public int subtractProductAndSum(int n) {
        int sum = 0;
        int product = 1;
        List<Integer> list = new ArrayList<>();

        while (n >= 10) {
            list.add(n % 10);
            n /= 10;
        }
        list.add(n);

        for (int x : list) {
            sum += x;
            product *= x;
        }
        return product - sum;
    }

    public static void main(String[] args) {
        LCode1281 lCode1281 = new LCode1281();
        System.out.println(lCode1281.subtractProductAndSum(234));
    }
}
